`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date: 2020/09/15 19:55:33
// Design Name: 
// Module Name: IsJump
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//////////////////////////////////////////////////////////////////////////////////
`include "opcode.v"
`include "funct.v"
`include "rt.v"


module IsJump(
//    input   wire [31:0] i_pc,
    input   wire [31:0] i_inst,
    input   wire [31:0] i_rs_out,
    input   wire [31:0] i_rt_out,
    
    output  wire        o_is_jump
    );
    
    wire [5:0] op;
    wire [4:0] rt;
    wire [5:0] funct;
    assign op = i_inst[31:26];
    assign rt = i_inst[20:16];
    assign funct = i_inst[5:0];
    
    wire z;
    wire gtz;
    wire ltz;
    wire eq;
    
    assign z = ~(|i_rs_out);
    assign gtz = i_rs_out[31] == 0 && z != 1;
    assign ltz = i_rs_out[31] == 1;
    assign eq = i_rs_out == i_rt_out;
    
    
    wire regimm;
    assign regimm
        = rt == `RT_BLTZ ? (ltz ? 1 : 0)
        : rt == `RT_BLTZAL ? (ltz ? 1 : 0)
        : rt == `RT_BGEZ ? (gtz || z ? 1 : 0)
        : rt == `RT_BGEZAL ? (gtz || z ? 1 : 0)
        : 0
    ;
    
    wire special;
    assign special
        = funct == `FUNCT_JR ? 1
        : funct == `FUNCT_JALR ? 1
        : 0
    ;
    
    assign o_is_jump
        = op == `OP_REGIMM ? regimm
        : op == `OP_SPECIAL ? special
        : op == `OP_BEQ ? (eq ? 1 : 0)
        : op == `OP_BGTZ ? (gtz ? 1 : 0)
        : op == `OP_BLEZ ? (ltz || z ? 1 : 0)
        : op == `OP_BNE ? (!eq ? 1 : 0)
        : op == `OP_J ? 1
        : op == `OP_JAL ? 1
        : 0
    ;
    
endmodule
